package projectmanagement.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import projectmanagement.util.ApplicationSecurityManager;
import projectmanager.model.dao.ProjectDao;

public class DeleteProjectController extends SimpleFormController {
	public static final String PROJECT_ID = "id";

	private ProjectDao projectManager;
	private ApplicationSecurityManager applicationSecurityManager;

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String id = request.getParameter(PROJECT_ID);

		if (id != null && id.trim().length() > 0) {
			projectManager.remove(Integer.parseInt(id));
		} else {
			throw new ServletException("Blogai nurodytas id.");
		}

		return new ModelAndView(getSuccessView());
	}

	public ProjectDao getProjectManager() {
		return projectManager;
	}

	public void setProjectManager(ProjectDao projectManager) {
		this.projectManager = projectManager;
	}

	public ApplicationSecurityManager getApplicationSecurityManager() {
		return applicationSecurityManager;
	}

	public void setApplicationSecurityManager(
			ApplicationSecurityManager applicationSecurityManager) {
		this.applicationSecurityManager = applicationSecurityManager;
	}
}
